<template>
  <div class="search-result">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" :key="item.art_id" :title="item.title" />
    </van-list>
  </div>
</template>

<script>
// 导入 api
import { getSearchResult } from '@/api/search.js'
export default {
  name: 'searchResult',
  props: {
    searchText: {
      type: String,
      require: true
    }
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1,
      pagesize: 20
    }
  },
  created() {},
  methods: {
    async onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      // 请求 搜索 结果 数据
      const { data } = await getSearchResult(
        this.searchText,
        this.page,
        this.pagesize
      )
      this.list.push(...data.data.results)
      // 加载状态结束
      this.loading = false
      // 数据全部加载完成
      if (data.data.results.length < this.pagesize) {
        this.finished = true
      } else {
        this.page++
      }
    }
  },
  computed: {},
  watch: {},
  components: {}
}
</script>

<style lang="less" scoped>
</style>
